home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
tvcolor.exe
/
TDEMO.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-06-27
|
21KB
|
733 lines
/*-----------------------------------------------------------------------*/
/* filename - TDemo.cpp */
/* */
/* function(s) */
/* definitions for TDemo class */
/* demonstrates use of the TVColorDialog library */
/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/
/* */
/* TDEMO.CPP */
/* */
/* Copyright (C) 1992 Michael Newton and Comsoft Software */
/* All Rights Reserved. */
/* */
/*-----------------------------------------------------------------------*/
#define Uses_TApplication
#define Uses_TBackground
#define Uses_TButton
#define Uses_TCheckBoxes
#define Uses_TCollection
#define Uses_TColorGroup
#define Uses_TColorItem
#define Uses_TDeskTop
#define Uses_TDialog
#define Uses_TEvent
#define Uses_TKeys
#define Uses_TLabel
#define Uses_TMenu
#define Uses_TMenuBar
#define Uses_TMenuItem
#define Uses_TObject
#define Uses_TPalette
#define Uses_TRect
#define Uses_TScreen
#define Uses_TStatusDef
#define Uses_TStatusItem
#define Uses_TStatusLine
#define Uses_TStaticText
#define Uses_TSItem
#define Uses_TSubMenu
#define Uses_TStreamable
#define Uses_TStreamableClass
#define Uses_TView
#define Uses_TWindow
#define Uses_ipstream
#define Uses_opstream
#define Uses_fpstream
#define Uses_MsgBox
#include <tv.h>
__link(RMenuBar)
__link(RPatternButtons)
__link(RPatternCluster)
__link(RRadioButtons)
__link(RResourceCollection)
__link(RStaticText)
__link(RVColorDialog)
// CRTL header files ******************************************************
#if !defined __STDLIB_H
#include <stdlib.h>
#endif
#if !defined __STDIO_H
#include <stdio.h>
#endif
#if !defined __STDARG_H
#include <stdarg.h>
#endif
#if !defined __CONIO_H
#include <conio.h>
#endif
#if !defined __IOSTREAM_H
#include <iostream.h>
#endif
#if !defined __STRSTREA_H
#include <strstrea.h>
#endif
#if !defined __FSTREAM_H
#include <fstream.h>
#endif
#if !defined __IOMANIP_H
#include <iomanip.h>
#endif
#if !defined __STRING_H
#include <string.h>
#endif
#if !defined __DOS_H
#include <dos.h>
#endif
#if !defined __DIR_H
#include <dir.h>
#endif
#if !defined __ALLOC_H
#include <alloc.h>
#endif
// non-CRTL header files **************************************************
#if !defined __TDEMO_HPP
#include "tdemo.hpp"
#endif
#if !defined __COLORDLG_HPP
#include "colordlg.hpp"
#endif
// External variables *****************************************************
extern TPoint shadowSize;
// TMenuItem **************************************************************
TMenuItem& operator +(TMenuItem& item1, TMenuItem& item2)
{
TMenuItem *temp = &item1;
while(temp->next != NULL)
temp = temp->next;
temp->next = &item2;
return item1;
}
// TDemo ******************************************************************
const char * near TDemo::configFile = "TDEMO.CFG";
TDemo::TDemo() : TProgInit(initStatusLine, initMenuBar, initDeskTop)
{
// This is the default palette for the application. If no configuration
// file is found, this palette will be copied into the applications
// palette.
// This palette was created by selecting "savePalette" on the menubar.
// SavePalette creates a text file named PALETTE.TXT, which will
// consist of an array similar to "defpal" below. The attributes in
// PALETTE.TXT will be the currently selected application's colors.
uchar defPal[] = {0x09,0x17,0x18,0x1F,0x0E,0x04,0x0F,0x10,0x17,0x0E,
0x09,0x1A,0x17,0x1C,0x1E,0x37,0x3F,0x0E,0x0C,0x13,
0x30,0x3C,0x00,0x78,0x70,0x0E,0x0E,0x13,0x70,0x40,
0x1E,0x78,0x70,0x0E,0x6E,0x4E,0x70,0x70,0x7E,0x7E,
0x30,0x3E,0x3F,0x37,0x3B,0x78,0x70,0x7E,0x7E,0x03,
0x4F,0x7E,0x5E,0x55,0x0B,0x3E,0x03,0x4F,0x0E,0x07,
0x0F,0x00,0x00,0x37,0x3F,0x3A,0x13,0x13,0x30,0x3E,
0x1E};
// Call the restoreDesk function to restore the desktop
// If a valid configuration file exists, restoreDesk will restore
// the desktop. If not, then we set the defaults
if(!restoreDesk())
{
// Set background pattern character to ascii 206 ╬
deskTop->background->setPattern(206);
// Save the pattern character in member variable
currentPattern = deskTop->background->getPattern();
// TPatternButtons start at 4
patternButtons = 4;
// Copy the default palette into the application's palette
TPalette &palette = getPalette();
ushort length = palette[0];
memmove(&palette[1], &defPal[0], (size_t) length);
// Redraw the desktop
setState(sfExposed, False);
setState(sfExposed, True);
redraw();
}
}
TDemo::~TDemo()
// For debugging only
{
}
TMenuBar *TDemo::initMenuBar(TRect r)
{
TMenuItem *sys =
new TMenuItem("~\360~", cmAbout, kbAltSpace, hcNone);
TMenuItem *exit =
new TMenuItem("E~x~it", cmQuit, kbAltX, hcNone);
TMenuItem *colors =
new TMenuItem("~C~olors", cmColors, kbNone, hcNone);
TMenuItem *pal =
new TMenuItem("~W~rite palette", cmSavPal, kbAltP, hcNone);
TMenu *menu = new TMenu(*sys + *exit + *colors + *pal);
r.b.y = r.a.y + 1;
return(new TMenuBar(r, menu));
}
TStatusLine *TDemo::initStatusLine(TRect r)
{
r.a.y = r.b.y - 1;
return new TStatusLine(r,
*new TStatusDef(0, 0xffff) +
*new TStatusItem("~Alt-X~ Exit", kbAltX, cmQuit) +
*new TStatusItem("~F10~ Menu", kbF10, cmMenu));
}
void TDemo::handleEvent(TEvent& event)
{
// If user selects "Exit", save the current desktop
if(event.what == evCommand && event.message.command == cmQuit)
{
if(!confirmExit()) // Get confirmation
clearEvent(event);
else
saveDesk(); // Save desktop before exiting
}
TApplication::handleEvent(event);
switch(event.what)
{
case evCommand:
switch(event.message.command)
{
case cmSavPal:
writePalette("palette.txt");
break;
case cmAbout:
about();
break;
case cmColors:
colors();
break;
}
break;
default:
return;
}
clearEvent(event);
}
void TDemo::about()
{
char *line[] = {
"TVColorDialog Demo",
"(C) Copyright 1992",
"Michael Newton and Comsoft Software",
"All rights reserved.",
"Demonstrates the TVColorDialog class."
};
TDialog *d = new TDialog(TRect(0, 0, 56, 13), "About");
TStaticText *t;
int len = strlen(line[0]);
t = new TStaticText(TRect(0, 2, len, 3), line[0]);
t->options |= ofCenterX;
d->insert(t);
len = strlen(line[1]);
t = new TStaticText(TRect(0, 4, len, 5), line[1]);
t->options |= ofCenterX;
d->insert(t);
len = strlen(line[2]);
t = new TStaticText(TRect(0, 5, len, 6), line[2]);
t->options |= ofCenterX;
d->insert(t);
len = strlen(line[3]);
t = new TStaticText(TRect(0, 6, len, 7), line[3]);
t->options |= ofCenterX;
d->insert(t);
len = strlen(line[4]);
t = new TStaticText(TRect(0, 8, len, 9), line[4]);
t->options |= ofCenterX;
d->insert(t);